import matplotlib.pyplot as plt
import numpy as np


def ellipse(a, b): # From (0, b) to (a, 0)
    # Constants
    [aa, ab, bb] = [a * a, a * b, b * b]
    # Initialize 1
    [x, y] = [0, b]
    pointlist = []
    p = bb - aa * b + aa / 4
    # Mid-Point Ellipse Algorithm 1
    while 2 * bb * x < 2 * aa * y:
        pointlist.append([x, y])
        if p < 0:
            [x, y, p] = [x + 1, y, p + 2 * bb * x + 3 * bb]
        else:
            [x, y, p] = [x + 1, y - 1, p + 2 * bb * x + 3 * bb - 2 * aa * (y - 1)]
    # Initialize 2
    p = bb * (x + 1 / 2) * (x + 1 / 2) + aa * (y - 1) * (y - 1) - aa * bb
    # Mid-Point Ellipse Algorithm 1
    while y >= 0:
        pointlist.append([x, y])
        if p > 0:
            [x, y, p] = [x, y - 1, p - 2 * aa * y + 3 * aa]
        else:
            [x, y, p] = [x + 1, y - 1, p - 2 * aa * y + 3 * aa + 2 * bb * (x + 1)]
    return pointlist


if __name__ == '__main__':
    pointList = ellipse(50, 10)
    for [x, y] in pointList:
        plt.plot(x, y, color='green', marker='o', linestyle='dashed', linewidth=1, markersize=1)
        plt.plot(-x, y, color='green', marker='o', linestyle='dashed', linewidth=1, markersize=1)
        plt.plot(x, -y, color='green', marker='o', linestyle='dashed', linewidth=1, markersize=1)
        plt.plot(-x, -y, color='green', marker='o', linestyle='dashed', linewidth=1, markersize=1)
    plt.xticks([-50, -40, -30, -20, -10, 0, 10, 20, 30, 40, 50])
    plt.yticks([-50, -40, -30, -20, -10, 0, 10, 20, 30, 40, 50])
    plt.show()